
#include "Item.h"

namespace mjc {

	Item::Item(const Object& obj)
		:kind(K_STACK),
		type(obj.GetType()),
		object(obj),
		value(0),
		address(0)
	{
		switch(object.GetKind())
		{
		case Object::K_CONSTANT:
			kind = K_CONSTANT;
			value = object.GetConstantData().GetValue();
			break;

		case Object::K_VARIABLE:
			address = object.GetVariableData().GetAddress();
			if(object.GetVariableData().GetLevel() == 0)
				kind = K_STATIC;
			else
				kind = K_LOCAL;
			break;

		case Object::K_METHOD:
			kind = K_METHOD;
			address = object.GetMethodData().GetAddress();
			break;
		}
	}

	Item::Item(const Object& obj, const Item::Kind& _kind)
		:kind(_kind),
		type(obj.GetType()),
		object(obj),
		value(0),
		address(0)
	{
		switch(object.GetKind())
		{
		case Object::K_CONSTANT:
			value = object.GetConstantData().GetValue();
			break;

		case Object::K_VARIABLE:
			address = object.GetVariableData().GetAddress();
			break;
		}
	}

	Item::Item(const mjc::Item &other)
		:kind(other.kind),
		type(other.type),
		object(other.object),
		value(other.value),
		address(other.address)
	{}

	Item& Item::operator = (const Item& other)
	{
		kind = other.kind;
		type = other.type;
		object = other.object;
		value = other.value;
		address = other.address;
		return *this;
	}

}